Comparing version 0.0.17 to 0.0.18
@@ -42,2 +42,3 @@ 'use strict' | ||
perspective, | ||
abilities, | ||
} | ||
@@ -44,0 +45,0 @@ return actor |
@@ -5,6 +5,12 @@ 'use strict' | ||
const abilities = newAbilities => { | ||
context.abilities = { ...context.abilities, ...newAbilities } | ||
Object.assign(abilities, context.abilities) | ||
return context.abilities | ||
} | ||
const actor = async (name, callbacks = {}) => { | ||
if (context.actors[name]) return context.actors[name] | ||
const newActor = (context.actors[name] = Actor( | ||
{}, | ||
{ ...abilities }, | ||
context.perspectives.default | ||
@@ -26,2 +32,3 @@ )) | ||
perspectives: {}, | ||
abilities: {}, | ||
} | ||
@@ -34,2 +41,3 @@ | ||
module.exports = { | ||
abilities, | ||
actor, | ||
@@ -36,0 +44,0 @@ perspective, |
@@ -6,3 +6,3 @@ 'use strict' | ||
const { Task } = require('./core') | ||
const { reset, actor, perspective } = require('./dsl') | ||
const { reset, actor, perspective, abilities } = require('./dsl') | ||
@@ -64,2 +64,20 @@ describe('feynman DSL', () => { | ||
describe('abilities', () => { | ||
it('sets and retrieves new abilities', () => { | ||
const xrayVision = 'an ability' | ||
abilities({ xrayVision }) | ||
assert.equal(abilities().xrayVision, xrayVision) | ||
assert.equal(abilities.xrayVision, xrayVision) | ||
}) | ||
it('creates actors with the set of abilities', async () => { | ||
const xrayVision = { look: sinon.spy() } | ||
abilities({ xrayVision }) | ||
const SeeThroughWalls = ({ xrayVision }) => xrayVision.look() | ||
const dave = await actor('dave') | ||
await dave.attemptsTo(SeeThroughWalls) | ||
sinon.assert.called(xrayVision.look) | ||
}) | ||
}) | ||
describe('resetting state between tests', () => { | ||
@@ -66,0 +84,0 @@ it('resets the actors', async () => { |
{ | ||
"name": "feynman", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "A screenplay pattern library for javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/feynman.js", |
@@ -40,16 +40,16 @@ # Feynman | ||
At its most basic, you give an `Actor` some `abilities` and then tell them to perform some `Actions`: | ||
Once you've defined your actions, you can ask an actor to attempt them: | ||
```javascript | ||
const { Actor } = require('feynman') | ||
const browser = require('create_browser')() | ||
const { Follow, Click, FillIn } = require('./actions') | ||
const browser = require('./create_browser')() | ||
const abilities = { browser } | ||
const Visit = { | ||
login: ({ browser }) => browser.get("https://localhost:5000/login") | ||
} | ||
const actor = Actor(abilities) | ||
actor.attemptsTo( | ||
Visit.login | ||
Follow.link("log in"), | ||
FillIn.fieldLabelled("email").with("matt@example.com"), | ||
FillIn.fieldLabelled("password").with("password"), | ||
Click.on("Log in") | ||
) | ||
@@ -59,3 +59,3 @@ ``` | ||
The whole set of abilities (in this case, just the `browser`) is passed to each action when it's attempted. The action | ||
can just pick out the abilities it needs to do its work. | ||
can just destructure the abilities it needs to do its work. | ||
@@ -71,6 +71,8 @@ There is one more ability too, which is where this pattern starts to get its power. | ||
const LogIn = { | ||
as: username => ({ actor, browser }) => { | ||
as: email => ({ actor, browser }) => { | ||
actor.attemptsTo( | ||
Visit.login, | ||
FillIn.label('username').with(username) | ||
Follow.link("log in"), | ||
FillIn.fieldLabelled("email").with(email), | ||
FillIn.fieldLabelled("password").with("password"), | ||
Click.on("Log in") | ||
) | ||
@@ -81,3 +83,3 @@ } | ||
const actor = Actor(abilities) | ||
actor.attemptsTo(LogIn.as("matt")) | ||
actor.attemptsTo(LogIn.as("matt@example.com")) | ||
``` | ||
@@ -84,0 +86,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32325583
576
202