npm install --save-dev jestyarn add --dev jest*.test.js
*.spec.js
__tests__/**/*.js
jestexpect(something)
.toBe(value)
.toEqual(value)
.toContain(item)
.toMatch(regexOrString)
.toHaveProperty(string)
...
.not.toBe / toEqual / ...jest --watchapi.js __mocks__/api.js
jest.mock('./path/to/api');
// imported api is mocked version
import { api } from './path/to/api';expect(serializedComponent)
.toMatchSnapshot();HelloWorld.vue HelloWorld.spec.js __snapshots__/HelloWorld.spec.js.snap
🤐
😝
(Tests / WebDriver client API)
(WebDriver protocol)
😭
npm install --save-dev cypressyarn add --dev cypresscypress opencypress rundescribe()
it()
beforeEach()
.only()
.skip()
// ...cy.stub()
cy.spy()expect(something)
.to.be.true
.to.equal(value)
.to.contain(value)
// ...cy.get('selector').find(node)
cy.get('nav a').first()
cy.get('nav').children()
cy.get('nav').parents()
// ....type('something') // {enter}, {backspace}
.click()
.dblclick()
.check() / .uncheck()
.select()
.focus() / .blur()
// ...cy.get('#header a')
.should('have.class', 'active')
.and('have.attr', 'href', '/users');cy.get('#header a')
.should($a => {
// perform some logic before assertions
expect($a).to.have.class('active');
expect($a).to.have.attr('href', '/users');
});Cypress.Commands.add('login', (username, password) => {
// command logic
});
it('should login', () => {
cy.login('john', '1234');
// ...
});// ...
cy.route('POST', '/api/login').as('login');
cy.get('button[type="submit"]')
.click();
cy.wait('@login');cy.route({
method: 'POST',
url: '/checkout',
response: {
items: ['product1', 'product2']
}
});debugger / .debug()