在 Lab 和 Code 中使用 enzyme

Lab 是一個用於 node 的簡單測試工具,同時也是 Hapi.js 框架的一部分。Lab 最初的程式碼大量取自 Mocha。而 Code 則為 Lab 的標準斷言函式庫,它是由 Chai 直接改寫而來。

範例測試:enzyme + Lab + Code

import { shallow, mount, render } from 'enzyme';
import React from 'react';

const Code = require('code');
const Lab = require('lab');

const lab = Lab.script();
exports.lab = lab;

lab.suite('A suite', () => {
  lab.test('calls componentDidMount', (done) => {
    const wrapper = mount(<Foo />);
    Code.expect(Foo.prototype.componentDidMount.callCount).to.equal(1);
    done();
  });
});

範例專案