angular-docs-cn/tools/transpiler/spec/functions_spec.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-09-30 16:25:20 -04:00
import {describe, ddescribe, it, iit, expect} from 'test_lib/test_lib';
2014-09-25 17:30:10 -04:00
function sum(a, b) {
return a + b;
}
2014-09-30 16:25:20 -04:00
export function main() {
describe('functions', function() {
it('should work', function() {
expect(sum(1, 2)).toBe(3);
});
2014-09-30 16:25:20 -04:00
describe("named parameters", function() {
it('should pass named params as named params by using identifier keys', function() {
function f(a, {b, c}) {return a + b + c;}
expect(f(1, {b: 2, c: 3})).toBe(6);
});
it('should pass named params as a map by using quoted keys', function() {
function f(m) {return m["a"] + m["b"];}
expect(f({"a": 1, "b": 2})).toBe(3);
});
it('should compile initializers', function() {
function f({a=1, b=2}) {return a + b;}
expect(f({a:10})).toBe(12);
});
it("should call function with named params without passing any" +
"params by providing an empty object initializer", function() {
function f({a=1, b=2}={}) {return a + b;}
expect(f({a: 10})).toBe(12);
expect(f()).toBe(3);
});
});
});
2014-09-25 17:30:10 -04:00
}