// describe(name, fn) cria um bloco que agrupa vários testes relacionados.
describe('Testing my application', () => {
...
});
// describe(name, fn) cria um bloco que agrupa vários testes relacionados.
describe('Testing my application', () => {
test('if it does this thing', () => {
...
});
it('should do the other thing', () => {
...
});
});
test('two plus two', () => {
const value = 2 + 2;
expect(value).toBeGreaterThan(3);
expect(value).toBeGreaterThanOrEqual(3.5);
expect(value).toBeLessThan(5);
expect(value).toBeLessThanOrEqual(4.5);
expect(value).toBe(4);
expect(value).toEqual(4);
});
test('is the same or not', () => {
const name = 'andre'
expect(name).toMatch(/dre/);
expect(name).not.toMatch(/I/);
expect(name).toBe('andre');
expect(name).toEqual('andre');
});
test('object assignment', () => {
const data = { one: 1 };
data.two = 2;
const expectedValue = { one: 1, two: 2 };
expect(data).toEqual(expectedValue);
});
test('list of games', () => {
const games = ['Mario', 'Sonic', 'Zelda'];
expect(games).toContain('Zelda');
expect(games).not.toContain('Resident Evil');
});
function errorMessage() {
throw new Error('Something is not Ok!!');
}
test('throwing an error', () => {
expect(() => compileAndroidCode()).toThrow();
expect(() => compileAndroidCode()).toThrow(Error);
// You can also use a string that must be contained in the error message or a regexp
expect(() => compileAndroidCode()).toThrowError('Something is not Ok!!');
expect(() => compileAndroidCode()).toThrowError(/Ok/);
});