mardi 27 octobre 2015

Chai-as-promise pass always the test

I have created this unit test:

import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';

import Request from '../src/request';

chai.use(chaiAsPromised);

describe('Request', () => {

    const hostname = 'http://localhost';
    let server;

    before(() => {
        server = sinon.fakeServer.create();
        server.respondWith(
            'GET',
            `${hostname}/api/entities`,
            [ 200, { 'Content-type': 'application/json' }, JSON.stringify({ entities: 1 })]
        );
    });

    it('Receive HTTP 200 status code from a GET request', () => {
        expect(new Request({ hostname }).get('/api/entities')).to.eventually.have.property('entities');
    });

    after(() => {
        server.restore();
    });
});

the point is that whatever I put on the property on the api it return successfully always. How is possible? there is something that it doesn't work.

Aucun commentaire:

Enregistrer un commentaire