Git Product home page Git Product logo

test-observer-spy's Introduction

@hirez_io/observer-spy Example

This repo contains a minimal reproduction of an odd behavior/bug with observer-spy and jest-auto-spies.

Setup

npm i
nx test demo

The Problem

See apps/demo/src/app/test/service.spec.ts and associated code.

It seems like @hirez_io/observer-spy does not deal with Observables that are created from Promises?

> nx run demo:test

 FAIL   demo  apps/demo/src/app/test/service.spec.ts
  ● TestService › works with subscribeSpyTo

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      20 |     expect(mock.getData).toHaveBeenCalled(); // <--- this passes and proves the observable is subscribed to
      21 |     expect(spy.receivedError()).toBe(false); // <--- this passes and proves there are no errors in the stream
    > 22 |     expect(spy.receivedNext()).toBe(true); // <--- this fails, which means the stream created by `from` doesn't emit any values?
         |                                ^
      23 |     expect(spy.getLastValue()).toEqual('test');
      24 |   });
      25 |

      at src/app/test/service.spec.ts:22:32

The Solution

Re-re-re-read the docs :)-< https://github.com/hirezio/observer-spy#-rxjs--promises-use-async--await

We need to use async/await when dealing with Promises

test-observer-spy's People

Contributors

rpd10 avatar

Watchers

 avatar Magz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.