change citations test to include default jspsych citation

This commit is contained in:
Cherrie Chang 2024-12-18 09:09:23 -05:00
parent 466b44c6ae
commit 5b64a47138

View File

@ -1,11 +1,10 @@
//import { JsPsych } from "../../src/JsPsych";
import { TestExtension } from "../extensions/TestExtension"; import { TestExtension } from "../extensions/TestExtension";
import TestPlugin from "../TestPlugin"; import TestPlugin from "../TestPlugin";
const jsPsychApaCitation = const jsPsychApaCitation =
"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 "; "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ";
const jsPsychBibtexCitation = const jsPsychBibtexCitation =
'@misc{LeeuwjsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, doi = {10.5281/zenodo.7702307}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, } @article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '; '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } ';
const testPluginApaCitation = "Test plugin APA citation"; const testPluginApaCitation = "Test plugin APA citation";
const testPluginBibtexCitation = "Test plugin BibTeX citation"; const testPluginBibtexCitation = "Test plugin BibTeX citation";
const testExtensionApaCitation = "Test extension APA citation"; const testExtensionApaCitation = "Test extension APA citation";
@ -37,7 +36,10 @@ try {
}); });
describe("citing not using an array", () => { describe("citing not using an array", () => {
test("citing nothing", () => { test("citing without input", () => {
expect(jspsych.getCitations()).toBe(jsPsychApaCitation);
});
test("citing null", () => {
expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions"); expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions");
}); });
test("citing without input and with invalid format", () => { test("citing without input and with invalid format", () => {
@ -49,20 +51,18 @@ try {
describe("citing using an array in different formats", () => { describe("citing using an array in different formats", () => {
test("citing empty array with APA format", () => { test("citing empty array with APA format", () => {
jspsych.getCitations([], "apa"); expect(jspsych.getCitations([], "apa")).toBe(jsPsychApaCitation);
expect(consoleWarnSpy.mock.calls[0][0]).toBe("No plugins/extensions provided");
}); });
test("citing empty array with BibTeX format", () => { test("citing empty array with BibTeX format", () => {
jspsych.getCitations([], "bibtex"); expect(jspsych.getCitations([], "bibtex")).toBe(jsPsychBibtexCitation);
expect(consoleWarnSpy.mock.calls[0][0]).toBe("No plugins/extensions provided");
}); });
test("citing empty array without format", () => { test("citing empty array without format", () => {
jspsych.getCitations([]); expect(jspsych.getCitations([])).toBe(jsPsychApaCitation);
expect(consoleWarnSpy.mock.calls[0][0]).toBe("No plugins/extensions provided");
}); });
test("citing one plugin with valid format in all caps", () => { test("citing one plugin with valid format in all caps", () => {
jspsych.getCitations([TestPlugin], "APA"); expect(jspsych.getCitations([TestPlugin], "APA")).toBe(
expect(consoleLogSpy.mock.calls[0][0]).toBe(testPluginApaCitation); jsPsychApaCitation + "\n" + testPluginApaCitation
);
}); });
test("citing with unsupported format", () => { test("citing with unsupported format", () => {
expect(() => jspsych.getCitations([TestPlugin], "DummyTex")).toThrow( expect(() => jspsych.getCitations([TestPlugin], "DummyTex")).toThrow(
@ -73,24 +73,24 @@ try {
describe("citing mix of valid plugins/extensions", () => { describe("citing mix of valid plugins/extensions", () => {
test("citing a plugin", () => { test("citing a plugin", () => {
jspsych.getCitations([TestPlugin]); expect(jspsych.getCitations([TestPlugin])).toBe(
expect(consoleLogSpy.mock.calls[0][0]).toBe(testPluginApaCitation); jsPsychApaCitation + "\n" + testPluginApaCitation
);
}); });
test("citing a plugin in BibTeX", () => { test("citing a plugin in BibTeX", () => {
jspsych.getCitations([TestPlugin], "bibtex"); expect(jspsych.getCitations([TestPlugin], "bibtex")).toBe(
expect(consoleLogSpy.mock.calls[0][0]).toBe(testPluginBibtexCitation); jsPsychBibtexCitation + "\n" + testPluginBibtexCitation
);
}); });
test("citing multiple plugins", () => { test("citing multiple plugins", () => {
jspsych.getCitations([TestPlugin, TestPlugin]); expect(jspsych.getCitations([TestPlugin, TestPlugin])).toBe(
expect(consoleLogSpy.mock.calls).toHaveLength(2); jsPsychApaCitation + "\n" + testPluginApaCitation
expect(consoleLogSpy.mock.calls[0][0]).toBe(testPluginApaCitation); );
expect(consoleLogSpy.mock.calls[1][0]).toBe(testPluginApaCitation);
}); });
test("citing mix of plugins and extensions", () => { test("citing mix of plugins and extensions", () => {
jspsych.getCitations([TestPlugin, TestExtension]); expect(jspsych.getCitations([TestPlugin, TestExtension])).toBe(
expect(consoleLogSpy.mock.calls).toHaveLength(2); jsPsychApaCitation + "\n" + testPluginApaCitation + "\n" + testExtensionApaCitation
expect(consoleLogSpy.mock.calls[0][0]).toBe(testPluginApaCitation); );
expect(consoleLogSpy.mock.calls[1][0]).toBe(testExtensionApaCitation);
}); });
}); });
} catch (e) { } catch (e) {