abruzzi / bookish

Bookish
0 stars 1 forks source link

sinon fake server #1

Open abruzzi opened 8 years ago

abruzzi commented 8 years ago
describe("fetch data from server", function() {
    var model;
    var server;

    var response = require('json!./fixtures/books.json');

    before(function() {
        server = sinon.fakeServer.create();
        server.respondWith("GET", "/books/1",
            [200, { "Content-Type": "application/json" },
                JSON.stringify(response)]);

        model = new Book();
    });

    after(function() {
        server.restore();
    });

    it("fetch data from remote", function(done) {
        model.fetch({
            success: function(data) {
                expect(book.name).toBe("JavaScript Core Concepts and Practises");
                done();
            }
        });

        server.respond();
    });

});
abruzzi commented 8 years ago
module.exports = {
    entry: {
        'test': 'mocha!./src/main/resources/static/specs/index.js'
    },
    output: {
        path: "tests/",
        filename: "[name].bundle.js",
        publicPath: '/tests'
    },
    devServer: {
        host: "localhost",
        port: "9100"
    }
};
var context = require.context('.', true, /.+Spec\.js?$/);
context.keys().forEach(context);

module.exports = context;
<!DOCTYPE html>
<html>
<head>
    <title>Mocha Specs</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./node_modules/mocha/mocha.css" />
    <script src="tests/test.bundle.js"></script>
</head>
<body>
</body>
</html>