Jest Snapshot Serializers

var ToDos = [
{ 'Id': '1', 'Title': 'Shop groceries', 'Status': 'done' },
{ 'Id': '2', 'Title': 'Go to gym', 'Status': 'pending' },
{ 'Id': '3', 'Title': 'Kill it with fire', 'Status': 'done' },
{ 'Id': '4', 'Title': 'Take snapshots', 'Status': 'done' },
{ 'Id': '5', 'Title': 'Be awesome', 'Status': 'pending' },
];
function filterTodos(arr, key, term) {
return arr.filter(function(obj) {
return obj[key] === term
});
}
test('it returns all todos with matching Id',() =>{
expect(filterTodos(ToDos,'Id', '1')).toMatchSnapshot()
})
test('it returns all todos with matching Title',() =>{
expect(
filterTodos(ToDos,'Title', 'Shop groceries')).toMatchSnapshot()

})
test('it returns all todos with matching Status',() =>{
expect(filterTodos(ToDos,'Done', 1)).toMatchSnapshot()
})
exports[`it returns all todos with matching Id 1`] = `
Array [
Object {
"Id": "1",
"Status": "done",
"Title": "Shop groceries",
},
]
`;
exports[`it returns all todos with matching Status 1`] = `
Array [
Object {
"Id": "1",
"Status": "done",
"Title": "Shop groceries",
},
Object {
"Id": "3",
"Status": "done",
"Title": "Kill it with fire",
},
Object {
"Id": "4",
"Status": "done",
"Title": "Take snapshots",
},
]
`;
exports[`it returns all todos with matching Title 1`] = `
Array [
Object {
"Id": "1",
"Status": "done",
"Title": "Shop groceries",
},
]
`;
expect.addSnapshotSerializer({
test:(val) => val.Id && val.Title && val.Status && val.expiration,
print:(val) => `ID: ${val.Id}
Title: ${val.Title}
Status: ${val.Status}
Expiration: ${val.expiration}`
})
// Jest Snapshot v1, https://goo.gl/fbAQLPexports[`it returns all todos with matching Id: 1 1`] = `
Array [
ID: 1
Title: Shop groceries
Status: done
Expiration: 23/03/17
,
]
`;
exports[`it returns all todos with matching Status: done 1`] = `
Array [
ID: 1
Title: Shop groceries
Status: done
Expiration: 23/03/17
,
ID: 3
Title: Kill it with fire
Status: done
Expiration: 23/03/17
,
ID: 4
Title: Take snapshots
Status: done
Expiration: 23/03/17
,
]
`;
exports[`it returns all todos with matching Title: Shop groceries 1`] = `
Array [
ID: 1
Title: Shop groceries
Status: done
Expiration: 23/03/17
,
]
`;

--

--

A frontend developer that can handle its dose of UX and design.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luis Vieira

Luis Vieira

A frontend developer that can handle its dose of UX and design.