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

How do I test an async void function using nuxt and jest? #9604

Closed
tkd-itsuki opened this issue Feb 20, 2020 · 2 comments
Closed

How do I test an async void function using nuxt and jest? #9604

tkd-itsuki opened this issue Feb 20, 2020 · 2 comments

Comments

@tkd-itsuki
Copy link

Say I have this async method called fetchItem() which calls an api wait for its return value and set the form to ready.

export default {
  components: {
    Header,
    Footer
  },
  data() {
    return {
      meeting: {},
      formReady: false,
      formAgree: false,
      ANSWER_TYPE: ANSWER_TYPE
    }
  },
  mounted() {
    this.fetchItem()
  },
  methods: {
    async fetchItem() {
      // wanted to test if meeting got data but I need $route to have params id
      this.meeting = await this.$MeetingApi.getMeeting(
        this.$route.params.id,
        false
      )
      this.formReady = true
      this.meeting.initAnswerBills()
    },
    async saveMeetingAnswer() {
     // I want to know if saveMeetingAnswer is called if I click the button( can't find by class name)
      this.formReady = false
      let save = await this.$MeetingApi.postAnswered(
        this.meeting.answeredFormData
      )
      this.formReady = true
    }
  }
}

How can I test this with jest async and mock function ? I read the documentation and I still have no clue how to implement the test.

@jeysal
Copy link
Contributor

jeysal commented Feb 20, 2020

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@jeysal jeysal closed this as completed Feb 20, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants