Zenika / react-workbench

Design your React component in an isolated context
MIT License
8 stars 1 forks source link

:white_check_mark: 'ddb' service #73

Closed bpetetot closed 7 years ago

bpetetot commented 7 years ago

6

bpetetot commented 7 years ago

@fabienjuif I have a problem with the test of ddb.append that I don't understand. An error occurred when I try to execute await ddb('name').append([]) in the test of append. FYI : if remove or skip all other tests, it works 😑 NEED HELP

fabienjuif commented 7 years ago

There is two problems I see :

  1. The mock are reset, so when you don't mock the implementation explicitly before calling the service, you are calling the node implementation
  2. The "default" mock (if not reset) readFileAsync returns undefined

Quick fix :

describe('server/api/ddb', () => {
  beforeEach(() => {
    fs.mkdirAsync.mockClear()
    fs.writeFileAsync.mockClear()
    fs.readFileAsync.mockClear()

    fs.mkdirAsync.mockImplementation(jest.fn(async () => undefined))
    fs.writeFileAsync.mockImplementation(jest.fn(async () => undefined))
    fs.readFileAsync.mockImplementation(jest.fn(async () => '[]'))
  })
bpetetot commented 7 years ago

@fabienjuif check it 🦄