Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add assertShape to validate templateElement (#10198)
* add assertShape to validate templateElement * Update packages/babel-types/src/definitions/utils.js Co-Authored-By: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> * templateElement optional cooked
- Loading branch information
1 parent
d3fe22f
commit ee68d6d
Showing
6 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
packages/babel-types/test/builders/es2015/__snapshots__/templateElement.js.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`builders es2015 templateElement should validate 1`] = ` | ||
Object { | ||
"tail": false, | ||
"type": "TemplateElement", | ||
"value": Object { | ||
"cooked": "foo", | ||
"raw": "foo", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`builders es2015 templateElement should validate 2`] = ` | ||
Object { | ||
"tail": false, | ||
"type": "TemplateElement", | ||
"value": Object { | ||
"raw": "foo", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`builders es2015 templateElement should validate 3`] = ` | ||
"Property value of TemplateElement expected to have the following: | ||
Property raw expected type of string but got number" | ||
`; | ||
|
||
exports[`builders es2015 templateElement should validate 4`] = ` | ||
"Property value of TemplateElement expected to have the following: | ||
Property cooked expected type of string but got number" | ||
`; | ||
|
||
exports[`builders es2015 templateElement should validate 5`] = ` | ||
"Property value of TemplateElement expected to have the following: | ||
Property raw expected type of string but got undefined" | ||
`; |
25 changes: 25 additions & 0 deletions
25
packages/babel-types/test/builders/es2015/templateElement.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as t from "../../.."; | ||
|
||
describe("builders", function() { | ||
describe("es2015", function() { | ||
describe("templateElement", function() { | ||
it("should validate", function() { | ||
expect( | ||
t.templateElement({ raw: "foo", cooked: "foo" }), | ||
).toMatchSnapshot(); | ||
|
||
expect(t.templateElement({ raw: "foo" })).toMatchSnapshot(); | ||
|
||
expect(() => | ||
t.templateElement({ raw: 1 }), | ||
).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => | ||
t.templateElement({ raw: "foo", cooked: 1 }), | ||
).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => t.templateElement("foo")).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |