Mock as iterable object
See original GitHub issueHello I had problem with expect(mock).toEqual(mock), because in a method toEqual be call iterator for the mock and own mock return not correct data for an iterator. You can see more information in https://medium.com/front-end-weekly/thank-u-symbol-iterator-next-aef9f09ff78. I used expect(mock.property).toEqual(mock.property)
interface SomeObject {
name: string;
}
it('should work', async () => {
const mockObject= mock<SomeObject>();
mockObject.name = 'mock';
expect(mockObject.name ).toEqual(name ); // that work correct
expect(mockObject).toEqual(mockObject); // Error
});
Example Error:
TypeError: Cannot read property 'next' of undefined
at Object.test (src\Mock.spec.ts:271:37)
at Object.asyncJestTest (node_modules\jest-jasmine2\build\jasmineAsyncInstall.js:102:37)
at resolve (node_modules\jest-jasmine2\build\queueRunner.js:43:12)
at new Promise (<anonymous>)
at mapper (node_modules\jest-jasmine2\build\queueRunner.js:26:19)
at promise.then (node_modules\jest-jasmine2\build\queueRunner.js:73:41)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mocking Iterable objects generically with Mockito
Mock the iterable's (the set) iterator() method to return a mock iterator; Mock the iterator's hasNext() method to return true N times followed...
Read more >Mock object is not iterable - python - Stack Overflow
When you create a mock, you sometimes have to let it know how to respond to some of the calls that will be...
Read more >Mocking __iter__ with a magic mock in Python
I was writing some tests in which I was mocking a dependency using ... The return value of MagicMock.iter can be any iterable...
Read more >Java mock iterable - gists · GitHub
public static <T> void mockIterable(Iterable<T> iterable, T... values) {. Iterator<T> mockIterator = mock(Iterator.class);. when(iterable.iterator()).
Read more >How to mock an iterator - Testing tips - Waiting For Code
method : "iterator" should "be mocked thanks to varargs from Mockito's thenReturn method" in { val mockedIterator ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jfemia that’s the exact error I’m getting. And I really, really, really would like to find a way to mock my interfaces rather than being forced to create a dummy object and then mocking that.
Same here with an angular 8.x app: