allain / expect

helpers for writing jest like expect tests in deno
ISC License
45 stars 14 forks source link

Modify mock afterwards #21

Closed ghost closed 2 years ago

ghost commented 2 years ago

I found a way with importmap and sinon to mock out a dependency.

https://stackoverflow.com/questions/69677679/deno-mock-out-named-import-in-unit-test/69682382#69682382

The great think about sinon is that I can modify the mock to behave how I want it.

beforeEach(() => {
    readJsonSync.withArgs(`./data.json`).returns(["hello"])
  })

The mock that comes from expect seems to lack a similar feature.

Sinon not seem to "play" with the expect. So can not do

expect(writeJsonSync).toHaveBeenCalledWith('./data.json', ["hello world"])

(yes did thi same post on tincan since I'm in doubt about where to start the discussion)