@jimmay5469
jimmylauzau.com
http://www.ember-cli-mirage.com/
A: A way to help you mock out an API for testing purposes.
A: Pretender focuses on mocking out endpoints, this focuses on loading the database of a fake server.
A: It has factory and fixture generation built in so you won't need to include a separate library for that.
A: In addition to running during testing, this fake server can also run during development!
A: learn to do four things:
Getting started...
// app/mirage/config.js export default function() { this.get('/users'); this.post('/users'); // These are shorthand for: // this.get('/users', function(db, request) { // return { // users: db.users // }; // }); // this.post('/users', function(db, request) { // var attrs = JSON.parse(request.requestBody); // var user = db.users.insert(attrs); // return user; // }); }
Note: we're gonna focus on doing things the factory way (instead of the fixture way)
// app/mirage/factories/user.js import Mirage, { faker } from 'ember-cli-mirage'; export default Mirage.Factory.extend({ name(i) { return `Person ${i}`; }, age: 28, admin: false, avatar: faker.internet.avatar });
// tests/acceptance/users-test.js test("I can view the users", function() { var users = server.createList('user', 3); visit('/users'); andThen(function() { equal( find('li').length, 3 ); equal( find('li:first').text(), users[0].name ); }); });
// app/mirage/scenarios/default.js export default function(server) { server.createList('post', 10); var user = server.create('user', {name: 'Zelda'}); server.createList('comment', 20, {user_id: user.id}); }
By Jimmy Lauzau
Getting started with the ember-cli-mirage addon.