Code Monkey home page Code Monkey logo

jasmine-example's Introduction

jasmine-example

Build Status

This is just a sandbox app for playing with some Jasmine tests, updated for September 2015.

Prerequisites:

  • Install Chrome browser (not mandatory, but is what's configured by default)
  • Install Node.js (currently v4.1.0, but anything over 0.10.25 should be workable)
  • Ensure you have an npm -v returns 2 or greater
  • Download PhantomJS and make sure it's available on your PATH by running phantomjs -v. It should be 1.9 or greater
  • Clone this repository and cd into it
  • Run npm install and it should exit cleanly

Validate installation

Run npm test and ensure the tests pass and that it exits cleanly

Running the test runner

While working on tests or code, start testem in interactive mode, which will launch an isolated Chrome instance:

$ npm start

You should see a runner like this:

screen shot 2015-09-20 at 17 37 36

To re-run your tests, either change a watched file, hit the Return / Enter key, or navigate to Chrome and refresh the test runner page.

What now?

First, keep a bookmark to this wiki on testing handy. We'll be referencing it a lot.

Second, visit the issues page and look through the issues Open for Voting. Feel free to 👍 up to 3 topics that you're most interested in, and we'll prioritize our time tackling those ones first!

jasmine-example's People

Contributors

searls avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

jasmine-example's Issues

Testing Node.js code

Review how to test Node.js code. This alone is a massive topic, but we can look at some examples, try to map your current approach to testing browser code and find as graceful a translation as possible.

Transpilers and testing

Using any transpilers like Babel/Traceur, CoffeeScript, Elm, PureScript, ClojureScript?

We can discuss:

  • Writing tests in the same or different language as the production code
  • Optimizing feedback loops
  • All the trade-offs therein

Compiling static assets & incorporating tests

Discuss how teams are currently compiling static assets for the web and how they might be improved, reviewing areas like:

  • Asset fingerprinting, manifest generations, and CDNs
  • Are builds progressive/iterative or all single-shot?
  • What are your current feedback loop speeds in development, CI, and deployment?
  • What are your biggest pain points?
  • How are tests currently integrated?
    • is there a development mode that automatically runs tests on file changes?
    • do development-mode test builds require wasteful build activities take place that aren't necessary (e.g. styles/fonts?)
    • do tests run against the actually-built code or do they duplicatively build the code using their own test-scoped transpilers, potentially letting bugs through (e.g. how karma plugins tend to compile separately from the main app)

Layers of testing (testing pyramid)

  • Identify the layers
  • Defining a test type that targets an individual layer
  • Why consistency matters
  • Trade-offs between design and safety link
  • My default advice free of situational context

The importance of consistency

We'll discuss why consistent-but-mediocre tests are almost always preferable to brilliant-but-creative tests within a suite.

  • Necessary & Sufficient
  • Memes like Subject/Result/Shape
  • Defining a discrete set of test suites by type, figuring out what test layers to avoid

Writing browser automation tests with JavaScript-based tools

There are lots of tools for writing Browser-automation tests in JavaScript, some integrating with test libs like mocha/jasmine/qunit, some that roll their own DSLs. Some examples:

  • Nightwatch
  • Zombie
  • Casper
  • Protractor
  • The Intern
  • Testium

I have project experience with most of these and can offer some advice and help on which to use (and why I currently tend to use none of them, in favor of Ruby & Capybara). That said, there are some interesting conversations to be had:

  • The perceived vs. actual benefit of JavaScripting all-the-things
  • The veritable graveyard of undermaintained and abandoned JS-based browser automation tools
  • The frustrations caused by the fact that Node.js only exposing async HTTP calls means that using the Selenium wire API requires a new async network request for each-and-every Selenium automation call. This can cause a ton of code organization pain without Promise-based abstractions all the way up.

Learning a test double (mocking) library

I recently wrote a new test double library called testdouble.js. It's a pretty complete test double library for most purposes and provides a cleaner API than Sinon.js. We can walk through the entirety of it in less than an hour and show how it'd be used in practice.

Ruby & Capybara

We have a lot of experience writing browser automation tests in Ruby & Capybara. If that's something folks are interested in, we can peel through examples and help identify low-hanging fruit for improving your tests

Application Frameworks and testing/TDD

How to approach testing (and especially TDD) when using an application framework.

We can discuss specific ones:

  • Backbone + Marionette
  • Angular
  • Ember

And how some framework's provided test types are worth skipping

JUnit & Selenium/WebDriver tests

For any folks doing JUnit & WebDriver for their browser automation tests, we can dig in and look at potetial ways to improve them based on common pitfalls and patterns that have worked well for us in the past.

How I write Jasmine tests of JavaScript code

This will get my own biases and experience on the table and show you how I work in a fresh environment. I'll show you the tools I prefer and do my best to explain why—only briefly contrasting them with alternatives. The goal here is to generate some discussion around how our approaches differ so we can learn from each other.

Controlling Test Data

It's generally very important for tests to control their data, both to ensure reliability (reduce erratic failures and test pollution) but also to maximize expressiveness (the ability to cleanly exercise the behavior you want to observe).

In unit tests, this is normally a function of building clean APIs that require a minimal amount of arrangement.

The challenge increases as tests become more integrated. A number of issues become interesting:

  • Factories, Fixtures, and their drawbacks
  • Creating, managing, and loading test databases
  • Writing tests of remotely deployed systems, locally running systems in a separate process, and running systems in the same process
  • Controlling test data for integration points you don't own (e.g. third party APIs)

Arranging DOM code with jasmine-fixture

It's really easy to assert the state of the DOM using jQuery's API, but it can be challenging to set up the same degree of specificity as tersely in your test setup. To that ends, I published jasmine-fixture years ago and we can walk through both how to use it and why it's superior to managing a set of shared view fixtures (or attempting to test against your app's actual views in unit tests)

https://github.com/searls/jasmine-fixture

Browser automation testing tips

There are a handful of pieces of general advice for writing solid browser automation tests we can review:

  • Selecting on user-visible text, and falling back on semantically meaningful attributes like rel as opposed to IDs & classes that are potentially significant to the implementation
  • Automating a11y testing
  • Superlinear build growth due to naive CRUD feature testing
  • After-action reports to actively identify and work to prevent against false negative test failures
  • Time-boxing the overall build to guard against bloat and ensure fast feedback

Modules and testing

  • Using ES6 modules with esparanto?
  • Using CommonJS modules with Node.js and/or browserify?
  • Using AMD with Require.js?

We can discuss ways to test code that's organized into modules, including:

  • Whether and how to organize your test code into modules as well
  • How to replace a module's dependencies with test doubles using sandboxed-module or proxyquire

How do *you* use JS testing libs

We'll take a survey of the attendees to do a quick show and tell by each group of exemplar tests, test running setups, etc. Then we'll use that as a jumping off point for constructive critique and feedback, while we absorb the context of the situation and try to understand what works and what doesn't.

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.