Git Product home page Git Product logo

Comments (3)

speedskater avatar speedskater commented on June 2, 2024

Maybe I have misunderstood you but I think you have an error in your export/import.

Either you should do default export which works as follows:

in WelcomePanel:

export default WelcomePanel;

in the test:

import ComponentToTest from './src/WelcomePanel';

Or you should used named exports in which case you should do:

in WelcomePanel
export class WelcomePanel ....

int the test:

import { WelcomePanel as ComponentToTest, Rewire, ResetDependency } .....

Or leave WelcomePanel as is and change the test code to:

import { assert } from 'chai';
import React, { Component } from 'react';
import { default as ComponentToTest } from 'modules/welcomePanel/welcomePanel.component';
'use strict'

describe('Tests General Configuration', function(){

it('should not be null', function(){

ComponentToTest.__Rewire__('node',"hey I'm mock")

let panel = new ComponentToTest.WelcomePanel();
panel.initPanel(document.body,`This is message no `);
assert.isNotNull("Basic Test");

//after test code otherwise it will not be called:

ComponentToTest.ResetDependency('node');
})
})

from babel-plugin-rewire.

speedskater avatar speedskater commented on June 2, 2024

@vnovick Does the previous comment solve your issue?

from babel-plugin-rewire.

vnovick avatar vnovick commented on June 2, 2024

The following helped. Thanks:

Welcome panel

import { node } from 'utils/dom';
import React from 'react';
import Card from 'components/card.component';

class WelcomePanel extends Card {
  constructor(props){
    super(props);
  }

  render() {
    return (
      <div className="welcome-panel">
         <Card content={node.toString()} />
      </div>
      )
  }

  initPanel(el,content){
    React.render( <WelcomePanel content={content} />, el);   
  }
}

export default { Class: WelcomePanel }

Test:

import { assert } from 'chai';
import React, { Component } from 'react';
import {Class as ComponentToTest, __Rewire__, __ResetDependency__ } from 'modules/welcomePanel/welcomePanel.component';
'use strict'

describe('Tests General Configuration', function(){


  it('should not be null', function(){

    __Rewire__('node',"hey I'm mock")

    let a = ['a','b','c'];
    for( let b of a){

    }

    let panel = new ComponentToTest
    panel.initPanel(document.body,`This is message no `)
    assert.isNotNull("Basic Test")
  })
})

__ResetDependency__('Card');

from babel-plugin-rewire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.