Skip to content

Instantly share code, notes, and snippets.

@assaf
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assaf/9674758 to your computer and use it in GitHub Desktop.
Save assaf/9674758 to your computer and use it in GitHub Desktop.
Mix use
// Liberally adapted from our test suites, which uses generators for complex steps (before/after/etc).
describe("With new customer", function() {
let business;
let customer1, customer2, customer3;
before(function*() {
// We have many tests, but you can only call listen() once
// on an HTTP server, so this is a case for resolve-once, and
// we use a promise.
yield Server.listen();
// This creates a new busines record in the database, with one
// user, one product. It returns a generator function that has
// multiple asynchronous steps, and return a model instance.
business = yield Helper.newBusiness();
// Let's add a customer. We're using an API that doesn't support
// promises or thunks because real life use case.
customer1 = new Customer({ business, name: "Assaf" });
yield (resume)=> customer1.save(resume);
// Now let's add two customers in parallel. The create method (new + save)
// takes set of properties and a callback, let's thunk those.
let create2 = Customer.create.bind(Customer, { business, name: "A" });
let create3 = Customer.create.bind(Customer, { business, name: "A" });
[customer2, customer3] = yield [one1, one2];
});
it("should .....")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment