Skip to content

Instantly share code, notes, and snippets.

View invoice-test.js
describe('GET /v2/invoices/{id}.html specs', function () {
describe('de', function () {
before(function () {
// call API and store response..
});
it('should return correct html', function () {
expect(beautify(this.response.payload)).toMatchSnapshot(this);
});
});
View makeTestTitle.js
export const makeTestTitle = test => {
let next = test;
const title = [];
for (;;) {
if (!next.parent) {
break;
}
title.push(next.title);
View expect-toMatchSnapshot-2.js
expect.extend({
toMatchSnapshot(ctx) {
if (!ctx || !ctx.test) {
throw new Error(
dedent(`missing \`ctx\` parameter for .toMatchSnapshot(),
did you forget to pass \`this\` expect().toMatchSnapshot(this)?`),
);
}
const { test } = ctx;
View expect-toMatchSnapshot.js
expect.extend({
toMatchSnapshot() {
// TODO: init testFile, testTitle
const result = toMatchSnapshot(this.actual, testFile, testTitle);
expect.assert(result.pass, !result.pass ? result.report() : '');
return this;
}
View toMatchSnapshot.js
import { SnapshotState, toMatchSnapshot } from ‘jest-snapshot’;
export function toMatchSnapshot(actual, testFile, testTitle) {
// Intilize the SnapshotState, it’s responsible for actually matching
 // actual snapshot with expected one and storing results to `__snapshots__` folder
 const snapshotState = new SnapshotState(testFile, {
  updateSnapshot: process.env.SNAPSHOT_UPDATE ? ‘all’ : ‘new’,
 });
// Bind the `toMatchSnapshot` to the object with snapshotState and
View expect-2.js
expect(response).toMatchSnapshot();
View expect.js
expect(response.data.headline).toEqual(‘Document #12–1332–11’);
expect(response.data.address.city).toEqual(‘Berlin’);
expect(response.data[0].line[0].total).toEqual(101);
expect(response.data[0].line[1].total).toEqual(102);
expect(response.data[0].line[2].total).toEqual(103);
expect(response.data[0].line[3].total).toEqual(104);
expect(response.data[1].line[0].total).toEqual(105);
expect(response.data[1].line[1].total).toEqual(106);
expect(response.data[1].line[2].total).toEqual(107);
expect(response.data[1].line[3].total).toEqual(108);
View get_invoices_html.js
/* eslint prefer-arrow-callback: 0 */
import expect from 'expect';
import moment from 'moment';
import timekeeper from 'timekeeper';
import beautify from 'js-beautify';
import * as apiUtils from '../../../helpers/api';
import * as serverUtils from '../../../helpers/server';
import * as mongoUtils from '../../../helpers/mongo';
View trackable.js
export function trackable(action, event, properties = {}) {
const analytics = {
eventType: event,
eventPayload: properties
};
return { ...action, meta: { analytics } };
}
View actions.js
import constants from '../../constants';
export function loadedDashboardState(website, status, news, revenues) {
return trackable({
type: constants.DASHBOARD_STATE_LOADED,
payload: { website, status, news, revenues }
},
'Dashboard opened', // <- event name
{ name: website.name } // <- additional event data
);
You can’t perform that action at this time.