Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeAll is execute after tests begins #124

Closed
DanielHGimenez opened this issue Apr 6, 2021 · 4 comments
Closed

beforeAll is execute after tests begins #124

DanielHGimenez opened this issue Apr 6, 2021 · 4 comments

Comments

@DanielHGimenez
Copy link

I'm using jest-cucumber to run my tests. In definition of feature, I call setup() method that will set beforeAll, beforeEach and afterEach callbacks. The beforeAll callback will execute startInTestMode method, which will get up the server application that will be used in tests. When I run the tests, things that should be defined in startInTestMode are not defined yet. When I debug de code, the beforeAll is executed after tests begins.

const feature = loadFeature(__dirname + '/../features/create_redirect_url.feature')

defineFeature(feature, test => {

    setup()

    test('Successfully create a url for new user', ({ given, when, then }) => {

        given('user is logged in', userIsLoggedIn())

        [...]
export default function setup() {
    beforeAll(async () => {
        await startInTestMode()    })
    beforeEach(async () => {
        await Cart.deleteMany({})
        nock.cleanAll()
    })
    afterAll(async () => {
        await MongoDbMock.stopDbMock()
    })
}

export async function startInTestMode() {
    DotenvConfig.configure()
    InversifyConfig.configure()
    ExpressConfig.configure()
    ApplicationConfig.configure()

    await MongoDbMock.initDbMock()
}
@bencompton
Copy link
Owner

I'm wondering if you meant given('user is logged in', () => userIsLoggedIn()) instead. I'm not sure what userIsLoggedIn is doing, but if that's actually performing logic that you'd expect to run when your tests execute, the way you have it now would run that logic immediately before your tests even start.

@DanielHGimenez
Copy link
Author

DanielHGimenez commented Apr 8, 2021

userIsLoggedIn is a method factory.

export function userIsLoggedIn() {
    return () => {
        nock(process.env.AUTH_URL!)
            .get('/auth')
            .reply(200, {
                id: 1
            })
    }
}

@DanielHGimenez
Copy link
Author

The problem is not in that function. In another function, I get data from process.env.KEY, which should be initialized when DotenvConfig.configure() is called. But the tests start, the Scenario begins, and beforeAll is not executed yet

@DanielHGimenez
Copy link
Author

Sorry, I made a mistake. The problem is not in jest-cucumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants