Code Monkey home page Code Monkey logo

Comments (6)

leojpod avatar leojpod commented on May 21, 2024

I've run into the same issue when trying to test the mouseover-ed feature.
I think what could be done is to overload the _destroyLater method instead of removing it.
Then we could for instance do something like this:

if the test should lead to _destroyLater being call:

FlashObject.reopen({_destroyLater: function () { ok(true, 'yes it was called!'); });

or ok(false) if the method shouldn't be called.

that being said... I haven't had time to try coding it since I thought about it and maybe it is a rubbish idea πŸ˜„

from ember-cli-flash.

jgwhite avatar jgwhite commented on May 21, 2024

A declarative public API for testing would be lovely.

This isn’t a serious suggestion, but food for thought:

test('say hello', function(assert) {
  visit('/');
  click('button:contains("Say hello"));
  pauseFlashes();
  andThen(() => { assert.equal(find(':contains("Hiya")').length, 1); });
  flushFlashes();
  andThen(() => { assert.equal(find(':contains("Hiya")').length, 0); });
});

from ember-cli-flash.

poteto avatar poteto commented on May 21, 2024

Thanks for reporting this @jgwhite and @leojpod! Yeah, it is definitely a problem I want to fix. I like the idea of being able to pause / flush flashes in testing, but I think I'd prefer for the flashes to just work in testing (without additional helpers) in a way that you'd expect. I'll investigate over the next few days to figure out the best approach.

from ember-cli-flash.

JarrodCTaylor avatar JarrodCTaylor commented on May 21, 2024

Here is another idea. I have ENV.stickyFlash = false set in environment.js (or some subset of flashMessageDefaults as explained in the README) then add messages with something like:

Ember.get(this, 'flashMessages').add({
  message: 'Custom message',
  sticky: ENV.stickyFlash
});

This just explicitly sets sticky to the already default false. Now in my test I have ENV.stickyFlash = true so the message is still present inside any andThen

from ember-cli-flash.

cowboyd avatar cowboyd commented on May 21, 2024

Using Mocha, the run.later for non-sticky flashes causes the _destroyLater hook to run immediately, which causes the tests asserting the existence of a flash to fail, but it's basically the same issue.

From my perspective, the most intuitive approach is to treat flashes as always sticky in test. That's because I almost always want to assert that they were shown, but I have complete faith that if I told ember-cli-flash that they should go away after five seconds, then they will. In the rare instances where you need to make assertions against a clean slate within the same test case, you could provide a clearFlashMessages helper.

Based on that, I think @jgwhite's workaround is the simplest, least surprising option, and I'd consider making it automatic. That way you spend basically zero mental overhead thinking about how your flashes might work differently in test than in development and production.

from ember-cli-flash.

poteto avatar poteto commented on May 21, 2024

Yeah, that's a good point @cowboyd, I like that approach and I'm gonna work on implementing that and the helper.

@JarrodCTaylor you can also set sticky: true inside of your dummy app's config/environment

from ember-cli-flash.

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.