jeudi 18 août 2016

Call single mocha test using webpack

I have a simple test where I'd like to test a service and it's method on front end. On the back-end I use require() to fetch modules but the front end uses webpack and import.

My test:

const testee = require('../network-template.service');

describe('getTemplates', function () {
    it('shall return templates from server', function (done) {
        console.log(testee);
        done();
    });
});

My test class:

import fetch from 'isomorphic-fetch';

const ENDPOINT = 'http://localhost:3000/api/network-templates';

class NetworkTemplateService {
    getTemplates(){
        return fetch(ENDPOINT, {
            method: 'GET',
            headers: {
                'Accept' : 'application/json'
            },
            body: JSON.stringify(ports)
        })
            .then(response => ({response}))
            .catch(error => ({error}));
    }

Is there a simple and fast way how to run this test? I like how on backend I am compiling nothing and can run all the tests immediately without any setup.

Aucun commentaire:

Enregistrer un commentaire