jeudi 26 mai 2016

mocha/chai testing as meteor package test: how to get dom elements or variable values

I'm writing my first test package for my meteor app with mocha. So I run a package test by doing meteor test-packages --driver-package practicalmeteor:mocha my:package.

package.js

Package.onTest(function(api) {
    api.use([
        'templating', 
        'ecmascript'
    ]);
    api.use('practicalmeteor:mocha');

    api.addFiles('tests/client.js', ['client']);
});

client.js

import { chai, expect, should } from 'meteor/practicalmeteor:chai';
chai.should();

describe('First module', function (done) {

    it("All needed elements existing", function(){
        should.exist($('#example'));    // doesn't work 
        expect($('#example'), 'example element').to.not.be.undefined;   // doesn't work either
    });
});

template

<template name="example">
    
        <h1>Restricted area</h1>
    
        <div id="#example">
            
                <p>is set</p>
            
                <p>is missing</p>
            
        </div>
    
</template>

helper

Template.example.helpers({
    session: function() {
        return !!(Session.get('anything'));
    }
})

So how would I test this very basic example. For me there are three problems:

  1. Do I have to take care of the alaning:roles thing?
  2. First I would check if dom elements are existing. But that doesn't work. Is that possible in a package test? Or is it a wrong thinking of mine?
  3. How can I test the Session-var?

Maybe I have a complete misunderstanding of doing a test, so I would appreciate any example how you would test this basic example. I've read tutorials for hours, but still have some problems to get started.

Aucun commentaire:

Enregistrer un commentaire