@willgmbr
NodeJS sem navegador
Diretamente no Navegador
Utilizando o KarmaJS
describe('UserService suite', () => {
it('should obtain the user token', () => {
});
});
describe('UserService suite', () => {
it('should obtain the user token', () => {
// Preparando Mock
const mockJWTService = jasmine
.createSpyObj('jwt', ['createToken']);
});
});
describe('UserService suite', () => {
it('should obtain the user token', () => {
// Preparando Mock
const mockJWTService = jasmine
.createSpyObj('jwt', ['createToken']);
// Preparando alvo do meu teste
const subject = new UserService(mockJWTService);
});
});
describe('UserService suite', () => {
it('should obtain the user token', () => {
// Preparando Mock
const mockJWTService = jasmine
.createSpyObj('jwt', ['createToken']);
// Preparando alvo do meu teste
const subject = new UserService(mockJWTService);
// Executando ação a ser testada
const token = subject.getToken();
});
});
describe('UserService suite', () => {
it('should obtain the user token', () => {
// Preparando Mock
const mockJWTService = jasmine
.createSpyObj('jwt', ['createToken']);
// Preparando alvo do meu teste
const subject = new UserService(mockJWTService);
// Executando ação a ser testada
const token = subject.getToken();
// Assert: Verificando o resultado esperado
expect(token).toBe('expected-token');
});
});
describe('MyComponent suite', () => {
describe('Internal logic', () => {
it('should change prop with method', () => {
const subject = new MyComponent();
subject.someMethod();
expect(subject.someProp).toBe('some-value');
});
});
});
describe('MyComponent suite', () => {
describe('Internal logic', () => {
it('should change prop with method', () => {
const subject = new MyComponent();
subject.someMethod();
expect(subject.someProp).toBe('some-value');
});
});
describe('UI interactions', () => {
it('should call method on button click', () => {
const subject = new MyComponent();
const container = $('<div>');
container.append(subject.element);
container.find('#button').click();
expect(subject.method).toHaveBeenCalled();
});
});
});
describe('google search suite', () => {
it('deve atualizar o título da página com a busca', () => {
browser.get('http://www.google.com');
element(by.name('q')).sendKeys('Julie');
element(by.name('btnG')).click();
expect(browser.getTitle()).toEqual('Julie - Google Search');
});
});
class GoogleSearchPage {
navigateTo() {
browser.get('http://www.google.com');
}
searchWith(query) {
element(by.name('q')).sendKeys(query);
element(by.name('btnG')).click();
}
}
describe('google search test', () => {
it('deve atualizar o título', () => {
const page = new GoogleSearchPage;
page.navigateTo();
page.searchWith('Julie');
expect(browser.getTitle())
.toEqual('Julie - Google Search');
});
});
@willgmbr