Я пытаюсь проверить вызов выборки с помощью Jest, и я использую метод expect.assertions()
, который я видел в учебнике.Примером, используемым в данный момент учебником, является метод fetchUser()
в объекте testingFunctions
.
Единственное отличие состоит в том, что fetchUser()
и fetchUser3()
в том, что первый использует axios.
Я получаю сообщение об ошибке теста: Expected one assertion to be called but received zero assertion calls.
const testingFunctions = {
fetchUser: () =>
axios
.get("https://jsonplaceholder.typicode.com/users/2")
.then(response => response.data)
.catch(err => "invalid fetch"),
fetchUser3: () => {
fetch("https://jsonplaceholder.typicode.com/users/3")
.then(response => response.json())
.catch(err => "Oh no");
}
};
test('should fetch and return an object with name of "Clementine Bauch"', () => {
expect.assertions(1);
return testingFunctions.fetchUser3().then(data => {
expect(data.name).toEqual("Clementine Bauch");
});
});
Есть идеи?