Skip to content

Commit

Permalink
feat: add test and testEach functions (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchelkowski authored Dec 1, 2023
1 parent ca29c34 commit 56f93c9
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 1,280 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
.idea/
.vscode/
dazn-kopytko-unit-testing-framework-*

node_modules/
.env

dazn-kopytko-unit-testing-framework-*
29 changes: 27 additions & 2 deletions docs/api/KopytkoTestFunctions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# KopytkoTestFunctions API

- [Functions](#functions)
- [`test`](#test)
- [`testEach`](#testeach)
- [`it`](#it)
- [`itEach`](#iteach)
- [`beforeAll`](#beforeall)
Expand Down Expand Up @@ -31,11 +33,34 @@ end function)

## Functions

### `test`

This is a shorthand for the `ts.addTest`.

```brs
test("it should check if true is true", function (_ts as Object) as String
return expect(true).toBeTrue()
end function)
```

### `testEach`

This is a shorthand for the `ts.addParameterizedTests`.

```brs
testEach([
{ value: 2, expectedValue: 2 },
{ value: "asd", expectedValue: "asd" },
], "it should check if ${value} is ${expectedValue}", function (_ts as Object, params as Object) as String
return expect(params.value).toBe(params.expectedValue)
end function)
```

### `it`

This is a shorthand for the `ts.addTest`.

It adds "it " to the beggining of thhe test name.
It adds "it " to the beggining of the test name.

```brs
it("should check if true is true", function (_ts as Object) as String
Expand All @@ -47,7 +72,7 @@ end function)

This is a shorthand for the `ts.addParameterizedTests`.

It adds "it " to the beggining of thhe test name.
It adds "it " to the beggining of the test name.

```brs
itEach([
Expand Down
6 changes: 3 additions & 3 deletions example/app/components/_tests/expectExamples.test.brs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ function TestSuite__expectExamples() as Object
' ---------------------------------------------------------
' toBeInvalid()
' ---------------------------------------------------------
it("expect(Invalid).toBeInvalid()", function () as String
test("it expect(Invalid).toBeInvalid()", function () as String
' Given
value = Invalid

' Then
return expect(value).toBeInvalid()
end function)

itEach([
testEach([
4,
true,
"Test Value",
{ key: "value" },
[1, 2, 3],
CreateObject("roSGNode", "rectangle"),
], "expect(nonInvalidValue).not.toBeInvalid()", function (value as Object) as String
], "it expect(nonInvalidValue).not.toBeInvalid()", function (value as Object) as String

' Then
return expect(value).not.toBeInvalid()
Expand Down
Loading

0 comments on commit 56f93c9

Please sign in to comment.