ManuelDeLeon / viewmodel-react

Create your React components with view models.
MIT License
24 stars 3 forks source link

Expose View Model methods using Jest #43

Open sirganya opened 6 years ago

sirganya commented 6 years ago

Is there a recommended strategy for importing a viewmodel into a Jest test and exposing it's methods for unit testing?

ManuelDeLeon commented 6 years ago

Import { YourComponent } from "./YourComponent"; Const yourComponent = new yourComponent();

See the testing section of the docs in basics and advanced.

On Tue, May 8, 2018, 8:13 AM Greg Kavanagh notifications@github.com wrote:

Is there a recommended strategy for importing a viewmodel into a Jest test and exposing it's methods for unit testing?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ManuelDeLeon/viewmodel-react/issues/43, or mute the thread https://github.com/notifications/unsubscribe-auth/AED31gC-6adCeHmN4PEO0LFuN9zw_UBaks5twafwgaJpZM4T2uLd .

sirganya commented 6 years ago

I should have specified that I'm using Blaze. Should it work similarly?

ManuelDeLeon commented 6 years ago

Ah, almost the same way. With

var vm = Template.name.createViewModel();
var vm = Template.name.createViewModel(obj_with_propreties_passed_down_to_template);

See the testing part of the PhoneBook example project: https://github.com/ManuelDeLeon/phonebook/tree/master/tests/mocha/client/viewmodels