I am learning Angular unit test for chained promise . Here is code snippet and failed at expectation with error message Expected ” to equal ‘bar’. What is needed to make it success ? I have used Angular 17 and Jasmine.I have tried with fakeAsync with tick & flush .
it(`nested promise testing`, fakeAsync(() => {
let item = '';
const mockItem = {
promise: Promise.resolve(new Response(JSON.stringify({ foo: 'bar' }))),
};
Promise.resolve(mockItem.promise)
.then((response) => response.json())
.then((data) => {
console.log('data = ' + data.foo);
item = data.foo;
});
flush();
//tick(500);
expect(item).toEqual('bar'); // Expected '' to equal 'bar'.
}));
New contributor
Jyoti Sahu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.