Dataform Javascript API Reference › Globals › "core/actions/test" › Test
Dataform test actions can be used to write unit tests for your generated SQL
You can create unit tests in the following ways.
Using a SQLX file:
-- definitions/name.sqlx
config {
type: "test"
}
input "foo" {
SELECT 1 AS bar
}
SELECT 1 AS barUsing the Javascript API:
// definitions/file.js
test("name")
.input("sample_data", `SELECT 1 AS bar`)
.expect(`SELECT 1 AS bar`);
publish("sample_data", { type: "table" }).query("SELECT 1 AS bar")Note: When using the Javascript API, methods in this class can be accessed by the returned value.
This is where input and expect come from.
-
ActionBuilder‹Test›
↳ Test
▸ dataset(ref: Resolvable): this
Sets the schema (BigQuery dataset) in which to create the output of this action.
Parameters:
| Name | Type |
|---|---|
ref |
Resolvable |
Returns: this
▸ expect(contextableQuery: Contextable‹IActionContext, string›): this
Sets the expected output of the query to being tested against.
Parameters:
| Name | Type |
|---|---|
contextableQuery |
Contextable‹IActionContext, string› |
Returns: this
▸ input(refName: string | string[], contextableQuery: Contextable‹IActionContext, string›): this
Sets the input query to unit test against.
Parameters:
| Name | Type |
|---|---|
refName |
string | string[] |
contextableQuery |
Contextable‹IActionContext, string› |
Returns: this