Skip to content

dogstyle/test

Repository files navigation

There have been recent updates that are not reflected in this readme .... be advised

Simple, integrated, console based testing for the PAGE framework

Allows easy initiation of testing over all testable code written within the PAGE(dog) framework. Download demo code, and run in a localHost. In a browser, open up your console (preferably in chrome) then type PAGE.runAllTests() to see results of example tests.

###Legend

Features

  • Asynchronous and synchronous testing
  • Dynamically load tests as seperate files.
  • Config based list of test files.
  • Tests are not loaded until you call PAGE.runAllTests(), saving bandwidth.
  • Tests are easily married to the PAGE framework constructors, modules, or Properties.
  • Tests can be broken out into individual test files for more portability.

Example

Functions to test

PAGE.add("Constructors.Dummy", function($base) {
  var dog = {
    addEasy : function(a,b) { return a+b }
    , $base : $base
    , changeInner : function(text) { $base.html(text); return this }
  }
  return dog
})

PAGE.add("Constructors.ReallyDumb", function() {
  var dog = { }

  dog.example = function(val, callback) {
    setTimeout(function() {
      callback(val)
    }, 1000)
    return this
  }

  return dog
})

Config

PAGE.wait("setTests", function(setTests) {
  setTests([
      "synchronousExample.js"
      , "asynchronousExample.js"
  ])
})

Config Free

As an alternative method to add tests, in which you can forego loading a config file, add the name of the test file as the third parameter of the PAGE.add method.

PAGE.add("Constructors.ReallyDumb", function() {
	...
}, "synchronousExample.js")

###Synchronous Testing

PAGE.addTests("Constructors.Dummy", function(Constructor, Test) {

  var $mock = $("<div>")
    , module = Constructor($mock)

  new Test("make sure it adds right", function() {
    return module.addEasy(1,2) === 4
  })

  new Test("make sure it changes the inner stuff", function() {
    module.changeInner("dog")
    return module.$base.html() === "dog"
  })

})

###Asynchronous Testing

PAGE.addTests("Constructors.ReallyDumb", function(ReallyDumb, Test, TestWaiter) {

  var module = ReallyDumb()

  new TestWaiter("Async Tests", function(series, go, call) {

    series.push(function() {
      module.example(42, function(val) {
        call({ result : (val === 42), name : "try async example" })
        go()
      })
    })

    series.push(function() {
      module.example(12, function(val) {
        call({ result : (val === 12), name : "try async example again" })
        go()
      })
    })

    go()
  })

})

Future Enhancements

Integrating the tests with automated building, TeamCity

About

test framework for PAGE

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published