question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mock as iterable object

See original GitHub issue

Hello 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rluggecommented, Mar 12, 2020

@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.

1reaction
viceicecommented, Jan 14, 2020

Same here with an angular 8.x app:

 TypeError: function is not iterable (cannot read property Symbol(Symbol.iterator))
        at new Set (<anonymous>)

      at _ValueOutputAstTransformer.visitStringMap (../packages/compiler/src/output/value_util.ts:29:23)
      at visitValue (../packages/compiler/src/util.ts:40:20)
      at ../packages/compiler/src/output/value_util.ts:32:38
          at Array.forEach (<anonymous>)
      at _ValueOutputAstTransformer.visitStringMap (../packages/compiler/src/output/value_util.ts:30:22)
      at visitValue (../packages/compiler/src/util.ts:40:20)
      at convertValueToOutputAst (../packages/compiler/src/output/value_util.ts:18:10)
      at singleProviderDef (../packages/compiler/src/view_compiler/provider_compiler.ts:116:22)
      at providerDef (node_modules/@angular/compiler/bundles/compiler.umd.js:22024:13)
      at ../packages/compiler/src/ng_module_compiler.ts:38:62
          at Array.map (<anonymous>)
      at NgModuleCompiler.compile (../packages/compiler/src/ng_module_compiler.ts:38:44)
      at JitCompiler._compileModule (../packages/compiler/src/jit/compiler.ts:153:52)
      at ../packages/compiler/src/jit/compiler.ts:119:31
      at Object.then (../packages/compiler/src/util.ts:89:74)
      at JitCompiler._compileModuleAndAllComponents (../packages/compiler/src/jit/compiler.ts:115:22)
      at JitCompiler.compileModuleAndAllComponentsSync (../packages/compiler/src/jit/compiler.ts:65:38)
      at CompilerImpl.compileModuleAndAllComponentsSync (../packages/platform-browser-dynamic/src/compiler_factory.ts:61:35)
      at TestingCompilerImpl.compileModuleAndAllComponentsSync (../../packages/platform-browser-dynamic/testing/src/compiler_factory.ts:52:27)
      at TestBedViewEngine._initIfNeeded (../../packages/core/testing/src/test_bed.ts:376:28)
      at TestBedViewEngine.createComponent (../../packages/core/testing/src/test_bed.ts:570:10)
      at Function.TestBedViewEngine.createComponent (../../packages/core/testing/src/test_bed.ts:232:36)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found