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

Unit testing #95

Closed
gdimitropoulos opened this issue Sep 25, 2021 · 4 comments
Closed

Unit testing #95

gdimitropoulos opened this issue Sep 25, 2021 · 4 comments

Comments

@gdimitropoulos
Copy link

gdimitropoulos commented Sep 25, 2021

Is there a way we can use unit testing with sandpack-react :


        const handleRefresh =  () => {
            // listens for any message dispatched between sandpack and the bundler
            
            const stopListening = listen((message) => console.log(message));
            // sends the refresh message to the bundler, should be logged by the listener
            dispatch({ type: "status", status: 'running-tests' });
            
            // unsubscribe
             stopListening();
            console.log("here")
          };                

should this do the trick?

@gdimitropoulos
Copy link
Author

For some reason even on the default example that you have on the docs, i can't see the message that it was suppose to get :

    const handleRefresh = async  () => {
            // listens for any message dispatched between sandpack and the bundler
            
            const stopListening = listen((message) => console.log(message));
            // sends the refresh message to the bundler, should be logged by the listener
            dispatch({ type: "refresh" });
            
            // unsubscribe
             stopListening();
            console.log("here")
          };

@gdimitropoulos
Copy link
Author

my solution to the above problem is :


    useEffect(() => {
      window.addEventListener('keydown',(event) => {
        console.log(event);
      });

      window.addEventListener('message', (event) => {
      // here i get all the responses from bundler 
        if (event.data.event == 'test_end') {
          if (event.data.test.status == 'fail') {
            dispatch({ type: 'refresh' });
          }
          statuses.push(event.data.test.status);
        }
        if(event.data.event =='total_test_end'){
          handleOpen();
        }

      });
    }, []);

@alexnm
Copy link
Collaborator

alexnm commented Oct 6, 2021

yes, unfortunately some of the message coming from / going to the bundler are not well documented/typed inside the bundler. can you share a full example of what you are trying to achieve? perhaps in a codesandbox link. we can integrate your example in our future showcase and document it better

@alexnm alexnm closed this as completed Oct 6, 2021
@danilowoz
Copy link
Member

@alexnm actually this issue was related to a misunderstanding in the documentation, and I opened a new issue to address it #96

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

3 participants