Skip to content

Commit

Permalink
fix(inheritance): ignore methods not found in test class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 14, 2023
1 parent 8cf9688 commit d7d99ff
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ process.env.IS_TS = 'true'
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*Test.ts'],
files: ['tests/Unit/**/*Test.ts'],
plugins: [assert()],
reporters: [specReporter()],
importer: Importer.import,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/test",
"version": "3.2.0",
"version": "3.2.1",
"description": "The Athenna test runner. Built on top of Japa.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
4 changes: 4 additions & 0 deletions src/Converters/TestConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class TestConverter {
* Convert test options of decorators to Japa test options.
*/
public static async convert(closure: any, options: TestOptions) {
if (!closure) {
return
}

const test = japaTest(options.title)

this.whenDefined(options.pin, () => test.pin())
Expand Down
10 changes: 9 additions & 1 deletion src/Helpers/Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export class Importer {
}

const test = new Test()
const bind = (method: string) => test[method].bind(test)
const bind = (method: string) => {
const closure = test[method]

if (!closure) {
return null
}

return closure.bind(test)
}

const {
tests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import { Test, TestContext } from '#src'
import { BaseTest } from '#tests/Stubs/BaseTest'

export default class InheritanceTest extends BaseTest {
export default class InheritanceOneTest extends BaseTest {
@Test()
public async shouldBeAbleToUseInheritanceInTestClasses({ assert }: TestContext) {
public async shouldBeAbleToUseInheritanceInTestInheritanceOneTestClass({ assert }: TestContext) {
assert.equal(this.BEFORE_EACH_EXECUTED, true)
}
}
18 changes: 18 additions & 0 deletions tests/Unit/InheritanceTwoTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @athenna/test
*
* (c) João Lenon <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { Test, TestContext } from '#src'
import { BaseTest } from '#tests/Stubs/BaseTest'

export default class InheritanceTwoTest extends BaseTest {
@Test()
public async shouldBeAbleToUseInheritanceInTestInheritanceTwoTestClass({ assert }: TestContext) {
assert.equal(this.BEFORE_EACH_EXECUTED, true)
}
}

0 comments on commit d7d99ff

Please sign in to comment.