Example #1
0
 test('does not write to the css file when it is the same as is already written', () => {
   fs.existsSync.mockReturnValueOnce(true)
   fs.readFileSync.mockReturnValueOnce(output)
   const { code } = transform(basic, {
     plugins: [[plugin, { extractStatic: true }]],
     filename: __filename,
     babelrc: false
   })
   expect(fs.existsSync).toBeCalledWith(cssFilepath)
   expect(touch.sync).not.toHaveBeenCalled()
   expect(fs.writeFileSync).not.toHaveBeenCalled()
   expect(code).toMatchSnapshot()
 })
Example #2
0
 test('writes to the css file when it does exist ', () => {
   fs.existsSync.mockReturnValueOnce(true)
   fs.readFileSync.mockReturnValueOnce('')
   const { code } = transform(basic, {
     plugins: [[plugin, { extractStatic: true }]],
     filename: __filename,
     babelrc: false
   })
   expect(fs.existsSync).toBeCalledWith(cssFilepath)
   expect(touch.sync).not.toHaveBeenCalled()
   expect(fs.writeFileSync).toHaveBeenCalledTimes(1)
   expect(fs.writeFileSync.mock.calls[0][0]).toBe(cssFilepath)
   expect(fs.writeFileSync.mock.calls[0][1]).toMatchSnapshot()
   expect(code).toMatchSnapshot()
 })