hirezio / auto-spies

Create automatic spies from classes
MIT License
181 stars 30 forks source link

Using nextWithValues with Observable properties does not work #49

Closed hlovdal closed 3 years ago

hlovdal commented 3 years ago

Describe the bug I encountered this while trying to fix a unit tests that still fails in an Angular 11 update attempt, where a component has an EventEmitter property. However Investigating further it boils down to the combination Observable + nextWithValues not working.

To Reproduce Steps to reproduce the behavior:

  1. Add the following tests in packages/jasmine-auto-spies/src/tests/observable-spy-utils.spec.ts under the "GIVEN observable spy is configured to emit" test (which ought to be renamed to "GIVEN observable spy is configured to emit a single value").
      fdescribe(`GIVEN observable spy is configured to emit multiple values`, () => {
        Given(() => {
          fakeClassSpy.observableProp.nextWithValues([
            { value: FAKE_VALUE + '1' },
            { value: FAKE_VALUE + '2' },
            { value: FAKE_VALUE + '3' },
            { complete: true },
          ]);
        });

        Then('return value should be the fake values', () => {
          expect(observerSpy.getValues()).toBe([
            FAKE_VALUE + '1',
            FAKE_VALUE + '2',
            FAKE_VALUE + '3',
          ]);
        });
      });
  1. Run yarn test:full.

Expected behavior

The test should not fail like the following:

FAILED TESTS:
        GIVEN observable spy is configured to emit multiple values
          ×
   -> Then return value should be the fake values
            Chrome Headless 90.0.4430.85 (Windows 10)
          Error: Expected [  ] to be [ [ 'FAKE EMITTED VALUE1', 'FAKE EMITTED VALUE2', 'FAKE EMITTED VALUE3' ]. Tip: To check for deep equality, use .toEqual() instead of .toBe() ].
              at <Jasmine>
              at UserContext.<anonymous> (webpack:///src/tests/observable-spy-utils.spec.ts:565:43 <- test.js:23:96914)
              at promisify (C:/git/github/auto-spies/node_modules/@hirez_io/jasmine-given/dist/jasmine-given.js:37:33)
              at C:/git/github/auto-spies/node_modules/@hirez_io/jasmine-given/dist/jasmine-given.js:283:36

TOTAL: 1 FAILED, 0 SUCCESS
shairez commented 3 years ago

Thanks for the report @hlovdal