Testing
Les Outils
Jasmine
Exemple avec Jasmine
Exécution des tests avec jasmine-node
jasmine-nodeJasmine's Spies
HTTP Testing
Last updated
jasmine-nodeLast updated
const cache = require('cache');
const User = require('user');
const Wish = require('wish');
describe('User', () => {
beforeEach(() => {
cache.clear();
});
afterEach(() => {
cache.clear();
});
it('should add wishes', function() {
const user = new User();
const wish = new Wish({title: 'Holidays'});
/* Add a wish. */
user.addWish(wish);
/* Check wishlist. */
expect(user.wishList().length).toEqual(1);
expect(user.wishList()[0].title()).toEqual('Holidays');
});
});yarn add --dev jasmine-node
yarn jasmine-node --autoTest --watchFolders app.js routes views test/unitdescribe('SearchEngine', () => {
it('should pass locale to third party api', () => {
/* Spying on `thirdPartySearchApi.search` and faking result. */
spyOn(thirdPartySearchApi, 'search').and.returnValue([
{
title: 'Wishtack - Making Your Wishes Come True',
url: 'https://www.wishtack.com'
}
]);
/* Trigger search. */
searchEngine.search({keywords: 'Wishtack'});
/* Check spy's call count. */
expect(thirdPartySearchApi.search.callCount).toBe(1);
/* Check spy's call args. */
expect(thirdPartySearchApi.search).toHaveBeenCalledWith({
country: 'US',
keywords: 'Wishtack',
language: 'en'
});
});
});const express = require('express');
const request = require('supertest');
describe('wishes RESTful API', () => {
it('should return wishes', (done) => {
request(app)
.get('/users/123456/wishes/')
.set('Accept', 'application/json')
.expect(200, [
{
id: 'abcdef',
title: 'Holidays'
}
], done);
});
});