Skip to content

Instantly share code, notes, and snippets.

@ilyavf
Last active November 2, 2016 23:02
Show Gist options
  • Save ilyavf/0f6b039676b6bff7f0e9f364d7c5c95e to your computer and use it in GitHub Desktop.
Save ilyavf/0f6b039676b6bff7f0e9f364d7c5c95e to your computer and use it in GitHub Desktop.
can-fixture-socket for test pages

Socket.io, can-fixture-socket and mocked services need to be evaluated before importing app models.

Async tests have to wait till dynamic import completes.

import QUnit from 'steal-qunit';
// Mock socket.io server:
import 'bitcentive/models/fixtures/fixtures-socket';
// Load viewmodel that will evaluate models:
var VMPromise = System.import('bitcentive/components/contribution-month/').then(module => module.ViewModel);
QUnit.asyncTest('test fixture socket', function(){
// Wait till our models get loaded:
VMPromise.then(ViewModel => {
let vm = new ViewModel({
contributionMonthId: "1"
});
vm.contributionMonthPromise.then((contributionMonth) => {
QUnit.equal(contributionMonth.monthlyOSProjects.length, 3, 'Loaded 3 OS projects');
QUnit.start();
});
});
});
import io from 'socket.io-client/socket.io';
import fixtureSocket from 'can-fixture-socket';
// Import `mock` functions for all services we need:
import mockContributionMonthsService from 'bitcentive/models/fixtures/contribution-months';
import mockOsProjectsService from 'bitcentive/models/fixtures/os-projects';
// Mock socket.io server with services:
var mockServer = new fixtureSocket.Server( io );
mockContributionMonthsService( mockServer );
mockOsProjectsService( mockServer );
import fixture from 'can-fixture';
import json from './contribution-months.json';
import canSet from 'can-set';
// TODO: import algebra from ContributionMonths model.
var contributionMonthStore = fixture.store(json, new canSet.Algebra(canSet.props.id('_id')));
export default function(mockServer){
mockServer.onFeathersService("api/contribution_months", contributionMonthStore, {id: "_id"});
}
[
{
"_id": "1",
"date": "2016-11-10T17:22:18.251Z",
"monthlyOSProjects": [{
"significance": 10,
"commissioned": true,
"osProjectRef": {
"_id": "1-CanJS",
"name": "CanJS"
}
},{
"significance": 20,
"commissioned": true,
"osProjectRef": {
"_id": "1-DoneJS",
"name": "DoneJS"
}
},{
"significance": 30,
"commissioned": true,
"osProjectRef": {
"_id": "1-StealJS",
"name": "StealJS"
}
}],
"monthlyClientProjects": []
},
{"_id": "2", "date": "2016-10-05T16:22:18.251Z"},
{"_id": "3", "date": "2016-19-01T15:22:18.251Z"}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment