Last active
February 21, 2016 03:55
-
-
Save morrissinger/6f638c04725d38155a88 to your computer and use it in GitHub Desktop.
Testing behavior in Koa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import koa from "koa" | |
import {behavior1} from "./behavior.js" | |
var app = koa(); | |
app.use(function* (next) { | |
this.body = yield behavior1(); | |
return yield next; | |
}); | |
app.listen(3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function asyncRequest () { | |
return new Promise((resolve, reject) => { | |
process.nextTick(() => { | |
resolve('Hello World'); | |
}); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Assert from "assert" | |
import {behavior1} from "./behavior.js" | |
describe('behavior', () => { | |
describe('behavior1', () => { | |
it('returns "Hello World"', function* () { | |
let body = yield behavior1(); | |
Assert.equal(body, 'Hello World'); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {asyncRequest} from "./async-request-mock.js" | |
export function* behavior1 () { | |
return yield asyncRequest(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment