import Sanity, { BetterCode } from 'ui-unit-tests';
By Cristian Oliveira
🇧🇷🇩🇪
Github: @cristianoliveira
Episode XX
It was in a time where big companies were ruling the whole culture.
The product planning and deliverying were very slow and burocratic.
The QA process were strict and heavily manual work were required.
Companies used to rely too much on manual testing in order to ensure the quality of their product.
That culture led to different kind of problems.
People were not happy also a lot of money and time were wasted....
Extreme Programming.
Fast product lifecycle.
Delivering fast and with quality.
Ensure quality by automated tests.
const component = shallow(< Component />);
For real unit testing. It doesn't render the component's children.
const component = mount(< Component />);
For Full DOM rendering. It's ideal for use cases where you have components
that may interact with DOM apis, or may require the full lifecycle.
function cityBirthday(content, city, year, month, day) {
let yearnumber = parseInt(year);
let birthday = new Date(year, month, day);
let today = new Date();
let year = today.getFullYear();
let age = year - birthday.getFullYear();
content += city.toUpperCase();
content += ' This year of ' + year + ' ';
content += 'the city is ' + age + ' years old.';
return content;
}
it("won't work, good luck", function() {
let result = cityBirthday('City: ', 'Foo', '2000', 05, 01);
expect(result).toEqual('???');
})
//Before each
const DATE_TO_USE = new Date('2016');
const _Date = Date;
global.Date = jest.fn(() => DATE_TO_USE);
global.Date.UTC = _Date.UTC;
global.Date.parse = _Date.parse;
global.Date.now = _Date.now;
it("shouldn't be that complicated to test", function() {
let result = cityBirthday('City: ', 'Foo', '2000', 05, 01);
expect(result).toEqual('???');
})