提交 1f1082f4 编写于 作者: 雪洛's avatar 雪洛

test: 增加解构默认值的测试

上级 c7760c23
...@@ -4,9 +4,9 @@ export function testType() : Result { ...@@ -4,9 +4,9 @@ export function testType() : Result {
return describe("Type", () => { return describe("Type", () => {
test("Object literal to type instance", () => { test("Object literal to type instance", () => {
type Person = { type Person = {
age: number age : number
} }
const a: Person = { const a : Person = {
age: 1 age: 1
} }
const b = { const b = {
...@@ -18,10 +18,10 @@ export function testType() : Result { ...@@ -18,10 +18,10 @@ export function testType() : Result {
}) })
test("Type with any[]", () => { test("Type with any[]", () => {
type Person = { type Person = {
age: number, age : number,
friends: any[] friends : any[]
} }
const a: Person = { const a : Person = {
age: 1, age: 1,
friends: ['b'] friends: ['b']
} }
...@@ -33,5 +33,24 @@ export function testType() : Result { ...@@ -33,5 +33,24 @@ export function testType() : Result {
expect(a instanceof Person).toEqual(true); expect(a instanceof Person).toEqual(true);
expect(b instanceof Person).toEqual(true); expect(b instanceof Person).toEqual(true);
}) })
test("destructure default value should override null", () => {
type Options = {
name : string
age ?: number
gender ?: number
}
const options = {
name: 'Tom'
} as Options
const {
name = 'testName',
age = 20,
gender
} = options;
expect(name).toEqual('Tom');
expect(age).toEqual(20);
expect(gender).toEqual(null);
})
}) })
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册