-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3167 from jspsych/skip-data-logging
Allow skipping data logging for a trial with `record_data: false`
- Loading branch information
Showing
9 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"jspsych": minor | ||
--- | ||
|
||
Added `record_data` as a parameter available for any trial. Setting `record_data: false` will prevent data from being stored in the jsPsych data object for that trial. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response"; | ||
import { pressKey, startTimeline } from "@jspsych/test-utils"; | ||
|
||
import { initJsPsych } from "../../src"; | ||
|
||
describe("The record_data parameter", () => { | ||
it("Defaults to true", async () => { | ||
const { getData } = await startTimeline([ | ||
{ | ||
type: htmlKeyboardResponse, | ||
stimulus: "<p>foo</p>", | ||
}, | ||
]); | ||
|
||
await pressKey(" "); | ||
|
||
expect(getData().count()).toBe(1); | ||
}); | ||
|
||
it("Can be set to false to prevent the data from being recorded", async () => { | ||
const onFinish = jest.fn(); | ||
const onTrialFinish = jest.fn(); | ||
const onDataUpdate = jest.fn(); | ||
|
||
const { getData } = await startTimeline( | ||
[ | ||
{ | ||
type: htmlKeyboardResponse, | ||
stimulus: "<p>foo</p>", | ||
record_data: false, | ||
on_finish: onFinish, | ||
}, | ||
], | ||
{ on_trial_finish: onTrialFinish, on_data_update: onDataUpdate } | ||
); | ||
|
||
await pressKey(" "); | ||
|
||
expect(getData().count()).toBe(0); | ||
expect(onFinish).toHaveBeenCalledWith(undefined); | ||
expect(onTrialFinish).toHaveBeenCalledWith(undefined); | ||
expect(onDataUpdate).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("Can be set as a timeline variable", async () => { | ||
const jsPsych = initJsPsych(); | ||
const { getData } = await startTimeline( | ||
[ | ||
{ | ||
timeline: [ | ||
{ | ||
type: htmlKeyboardResponse, | ||
stimulus: "<p>foo</p>", | ||
record_data: jsPsych.timelineVariable("record_data"), | ||
}, | ||
], | ||
timeline_variables: [{ record_data: true }, { record_data: false }], | ||
}, | ||
], | ||
jsPsych | ||
); | ||
|
||
await pressKey(" "); | ||
await pressKey(" "); | ||
|
||
expect(getData().count()).toBe(1); | ||
}); | ||
|
||
it("Can be set as a function", async () => { | ||
const jsPsych = initJsPsych(); | ||
const { getData } = await startTimeline( | ||
[ | ||
{ | ||
type: htmlKeyboardResponse, | ||
stimulus: "<p>foo</p>", | ||
record_data: () => false, | ||
}, | ||
], | ||
jsPsych | ||
); | ||
|
||
await pressKey(" "); | ||
|
||
expect(getData().count()).toBe(0); | ||
}); | ||
}); |