Code Monkey home page Code Monkey logo

Comments (6)

LRP-sgravel avatar LRP-sgravel commented on June 3, 2024

See PR#30 for fix

from wp-browser.

lucatume avatar lucatume commented on June 3, 2024

I've closed the PR not out of spite but to open one that deals with my code only and not the one that's in src/includes.
Could you paste a piece of the code you are testing to have a context?

from wp-browser.

LRP-sgravel avatar LRP-sgravel commented on June 3, 2024

This is a case I often have because I like regrouping all my exception/error handling for a given case in a single test. Arguably not the best practice but usually they look something like this:

    public function testExperimentSaveFailures()
    {
        global $experiments_model;

        $testExperiment = $experiments_model->createPendingExperimentModel('SaveAjaxTest', $this->validAccountId, $this->validPropertyId, $this->validViewId);

        try
        {
            // No experiment Id
            $this->_handleAjax('save_experiment');
        }
        catch(WPAjaxDieContinueException $e)
        {
            $response = json_decode($this->_last_response);

            $this->assertNotNull($response);
            $this->assertNotEmpty($response->error);
        }

        $_POST['experimentId'] = $testExperiment->getDBId();

        try
        {
            // No name
            $this->_last_response = NULL;
            $this->_handleAjax('save_experiment');
        }
        catch(WPAjaxDieContinueException $e)
        {
            $response = json_decode($this->_last_response);

            $this->assertNotNull($response);
            $this->assertNotEmpty($response->error);
        }

...

from wp-browser.

lucatume avatar lucatume commented on June 3, 2024

These should be, in strict TDD terms, all be different test cases.
If one of the tests is not throwing the test will pass; I'd separate them and use $this->setExpectedException in each. This way you are making sure an exception is thrown when you expect it to. Something like this:

public function testExperimentSaveFailsWithNoID() {
        global $experiments_model;

        $testExperiment = $experiments_model->createPendingExperimentModel('SaveAjaxTest', $this->validAccountId, $this->validPropertyId, $this->validViewId);

    $this->setExpectedException('WPAjaxDieContinueException');

    $this->_handleAjax('save_experiment');

    $response = json_decode($this->_last_response);

            $this->assertNotNull($response);
            $this->assertNotEmpty($response->error);
}

and replicate for each.
I'm not keen on introducing such a method but I'm open to a contextualised and well done PR.

from wp-browser.

LRP-sgravel avatar LRP-sgravel commented on June 3, 2024

Sure this is another approach but it's besides the point. I see no reason why a functional test should not have multiple Ajax calls in a single test.

I can just create my own helper to fix this simple problem but others might also want it...

from wp-browser.

lucatume avatar lucatume commented on June 3, 2024

I'm not keen on introducing such a method but I'm open to a contextualised and well done PR.

Well: make it and open a PR!

from wp-browser.

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.