ember-notify icon indicating copy to clipboard operation
ember-notify copied to clipboard

Acceptance Tests...again

Open gte451f opened this issue 9 years ago • 6 comments

I see that this has popped up here and there in previous issue but I am completely lost on how to verify success or failure on my tests.

Some examples seem to indicate you turn on alerts during testing but that slows things down: // my-acceptence-test.js import Notify from 'ember-notify'; Notify.testing = true;

I just want to detect if a notify.success() or notify.alert() is called from within the test. I've seen suggestions like "stub out notify.success" and to spy this.notify.alert() but I have no idea how to do that within a test.

Could someone give me a pointing to detect when success() or alert() is called from within an Acceptance test?

gte451f avatar Jul 20 '16 01:07 gte451f

I'm struggling with this in 2018 too. I love this library, but this is backbreaking.

plicjo avatar May 02 '18 20:05 plicjo

I'm able to acceptance test Ember Notify when it's configured to never close the alert.

I have a setting in my application controller that makes the alert never close in the test environment, but it works as normal in my production/development environment.

app/templates/application.hbs

{{outlet}}
{{ember-notify closeAfter=closeAfter}}

I then configure the library to not close in my application controller.

app/controllers/application.js

import Controller from '@ember/controller';
import config from '../config/environment';
import { computed } from '@ember/object';

export default Controller.extend({
  closeAfter: computed(function() {
    return config.environment == 'test' ? null : 5000;
  }),
});

And my acceptance tests are working fine!

plicjo avatar May 02 '18 20:05 plicjo

Is there a better alternative?

knownasilya avatar Jul 08 '18 18:07 knownasilya

Cc @rwjblue is there a standard or recommended way?

knownasilya avatar Jul 09 '18 01:07 knownasilya

As a user of Bulma, and specifically, bulma-toast, and since I'm thinking about using this library instead of bulma-toast, and am also struggling with acceptance testing toasts... I'm very interested in the solution to this :)

NullVoxPopuli avatar Aug 19 '18 11:08 NullVoxPopuli

I just ran into the same issue. Prior to Ember 3 we had been stubbing the notify service and while I was refactoring the acceptance tests I was seeing this.get('source').setTarget is not a function when registering the stub in the beforeEach hook.

The ember-notify component lives in our application template and we already had a computed prop setup to read the ENV from the config so conditionally rendering the ember-notify component fixed the issue.

{{#unless isTesting}}
  {{ember-notify closeAfter=3500}}
{{/unless}}

And the stub looks like...

export default Service.extend({
  lastMessage: null,

  alert(msg) {
    this.set('lastMessage', msg);
    console.log('Notify: '+msg);
  },
  info(msg) {
    this.set('lastMessage', msg);
    console.log('Notify: '+msg);
  },
  success(msg) {
    this.set('lastMessage', msg);
    console.log('Notify: '+msg);
  },
  warning(msg) {
    this.set('lastMessage', msg);
    console.log('Notify: '+msg);
  }
});

Register the stub...

import notifyStub from '/path-to-stub';
module('Application test name', function(hooks) {
  setupApplicationTest(hooks);
  hooks.beforeEach(function() {
    this.owner.register('service:notify', notifyStub);
  });
});

After that I can see the logs from the stub firing again and ember-notify is no longer throwing any errors.

zofskeez avatar Jun 18 '19 17:06 zofskeez