Skip to content

Instantly share code, notes, and snippets.

@rentan
Created June 2, 2014 15:19
Show Gist options
  • Save rentan/5099df90327e9ddae5ef to your computer and use it in GitHub Desktop.
Save rentan/5099df90327e9ddae5ef to your computer and use it in GitHub Desktop.
var customMatchers = {
toStartWith: function (util, customEqualityTesters) {
return {
compare: function (actual, expected) {
return { pass: actual.slice (0, expected.length) === expected };
}
};
}
};
describe ('test', function () {
it ('test 1', function () {
// it() 単位でのみ有効
jasmine.addMatchers (customMatchers);
expect ('foobar').toStartWith ('foo');
expect ('abc').not.toStartWith ('foo');
});
xit ('test 2', function () {
// ここではカスタムマッチャーが登録されてないのでエラーになる
expect ('foobar').toStartWith ('foo');
expect ('abc').not.toStartWith ('foo');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment