Skip to content

Instantly share code, notes, and snippets.

@tomduncalf
Last active August 29, 2015 14:14
Show Gist options
  • Save tomduncalf/8077681a597c9bc3b8ab to your computer and use it in GitHub Desktop.
Save tomduncalf/8077681a597c9bc3b8ab to your computer and use it in GitHub Desktop.
Attempt at a custom Jasmine matcher for ES6 Map equality testing, using the spread operator
import cfg from '../lib/config-parser';
var customMatchers = {
toEqualMap: (util, customEqualityTesters) => {
return {
compare: (actual, expected) => {
var result = {};
result.pass = util.equals([...actual], [...expected], customEqualityTesters);
if(!result.pass) {
result.message = `Expected map:\n${[...actual]} to equal\n${[...expected]}`;
}
return result;
}
};
}
};
describe("Config parser", () => {
beforeEach(() => {
jasmine.addMatchers(customMatchers);
});
it("should parse an empty config", () => {
var result = cfg.parse('');
var expected = new Map([]);
expect(result).toEqualMap(expected);
});
it("should parse a config with no sections", () => {
var result = cfg.parse(`key1 = value1
key2 = value2
key with spaces = value with spaces
akey = avalue`);
var expected = new Map([
['key1', 'value1'],
['key2', 'value2'],
['key with spaces', 'value with spaces'],
['akey', 'avalue']
]);
expect(result).toEqualMap(expected);
});
});
@tomduncalf
Copy link
Author

Any feedback welcome as I am not sure if this is a good way to do this or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment