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

When a test should return undefined, it returns the latest result (if exists) #1326

Closed
1 of 4 tasks
weisslertal opened this issue May 18, 2022 · 1 comment
Closed
1 of 4 tasks

Comments

@weisslertal
Copy link
Contributor

I'm submitting a...

  • Bug report
  • Feature request
  • Documentation issue or request
  • Other... Please describe:

Bug description

In tests, if a previous test returned a value then a following test that was supposed to return undefined will also return that value instead of undefined.

import { App, BaseComponent, Component, Global, Handle, InputType, TestSuite } from '@jovotech/framework';

@Global()
@Component()
export class GlobalComponent extends BaseComponent {
   @Handle({ intents: ['BuzzIntent'], global: true })
   public Buzz() {
       return this.$send({ message: 'pizza resp', listen: false });
   }

   @Handle({ intents: ['FooIntent'], global: true })
   public lovesPizza() {
       return this.$send({ message: undefined, listen: false });
   }

   @Handle({ intents: ['BarIntent'], global: true })
   public bar() {
       return this.$send({ message: 'bar', listen: false });
   }
}

const testApp = new App({
   plugins: [],
   components: [GlobalComponent],
});

const testSuite = new TestSuite({ app: testApp });

describe('describe', () => {
   test('should return pizza resp', async () => {
       const { output } = await testSuite.run({
           type: InputType.Intent,
           intent: 'BuzzIntent',
       });

       expect(output).toEqual([
           {
               listen: false,
               message: 'pizza resp',
           },
       ]);
   });

   test('should return nothing', async () => {
       const { output } = await testSuite.run({
           type: InputType.Intent,
           intent: 'FooIntent',
       });

       expect(output).toEqual([
           {
               message: undefined,
               listen: false,
           },
       ]);
   });

   test('should return bar', async () => {
       const { output } = await testSuite.run({
           type: InputType.Intent,
           intent: 'BarIntent',
       });

       expect(output).toEqual([
           {
               message: 'bar',
               listen: false,
           },
       ]);
   });
});

In the described test, we expect all three tests to pass. However, the second one fails because it returns 'pizza resp' (which is the return value from the first test. If the second one is run by itself then it passes. As seen in the third test (that always passes), when returning a value again then it does override the first value and works fine.

Your Environment

  • Jovo Framework version used: 4.2.14
  • Operating System: Mac OS (M1)
  • Node: 16.13.0
  • Jest: ^27.3.1
aswetlow added a commit that referenced this issue May 18, 2022
@jankoenig
Copy link
Member

Fixed by @aswetlow! Thanks Alex, and @weisslertal for the detailed issue description 🎉

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