<commit_before>"use strict"

var assert = require('chai').assert
var xdTesting = require('../../lib/index')
var templates = require('../../lib/templates')
var q = require('q')

describe('MultiDevice - selectAny', function () {
    it('should select a single device @medium', function () {
        var scenario = {
            A: templates.devices.chrome(),
            B: templates.devices.chrome()
        }

        return xdTesting.multiremote(scenario)
            .getCount().then(count => assert.equal(count, 2))
            .selectAny(device => device
                .getCount().then(count => assert.equal(count, 1))
            )
    })

    it('should execute promises callback @medium', function () {
        var scenario = {
            A: templates.devices.chrome(),
            B: templates.devices.chrome()
        }

        var queue = ''
        return xdTesting.multiremote(scenario)
            .then(() => queue += '0')
            .selectAny(device => {
                queue += '1'
                return device.then(() => {
                    queue += '2'
                })
            })
            .then(() => queue += '3')
            .then(() => assert.equal(queue, '0123'))
    })

    describe('on empty device sets', function() {

        it('should throw an error on command execution', function() {
            var scenario = {
            }

            var queue = ''
            return xdTesting.multiremote(scenario)
                .then(() => queue += '0')
                .selectAny(device => device
                    .click('#button')
                )
                .then(result => {
                    throw new Error('Promise was unexpectedly fulfilled. Result: ' + result)
                }, err => {
                    assert.instanceOf(err, Error)
                    assert.match(err.message, /not defined/)
                })
        })
    })
})
<commit_msg>Document selectAny throws error if applied to empty selections<commit_after>"use strict"

var assert = require('chai').assert
var xdTesting = require('../../lib/index')
var templates = require('../../lib/templates')
var q = require('q')

describe('MultiDevice - selectAny', function () {
    it('should select a single device @medium', function () {
        var scenario = {
            A: templates.devices.chrome(),
            B: templates.devices.chrome()
        }

        return xdTesting.multiremote(scenario)
            .getCount().then(count => assert.equal(count, 2))
            .selectAny(device => device
                .getCount().then(count => assert.equal(count, 1))
            )
    })

    it('should execute promises callback @medium', function () {
        var scenario = {
            A: templates.devices.chrome(),
            B: templates.devices.chrome()
        }

        var queue = ''
        return xdTesting.multiremote(scenario)
            .then(() => queue += '0')
            .selectAny(device => {
                queue += '1'
                return device.then(() => {
                    queue += '2'
                })
            })
            .then(() => queue += '3')
            .then(() => assert.equal(queue, '0123'))
    })

    describe('on empty device sets', function() {

        it('should throw an error on command execution', function() {
            var scenario = {
            }

            var queue = ''
            return xdTesting.multiremote(scenario)
                .then(() => queue += '0')
                .selectAny(device => device
                    .click('#button')
                )
                .then(result => {
                    throw new Error('Promise was unexpectedly fulfilled. Result: ' + result)
                }, err => {
                    assert.instanceOf(err, Error)
                    assert.match(err.message, /not defined/)
                })
        })
    })

    describe('on empty device selection', function() {

        /**
         * This throws the error as expected, but we cannot grab it. Skip the test until we found a solution.
         */
        it.skip('should throw an error on command execution', function() {
            var scenario = {
                A: templates.devices.chrome()
            }

            var queue = ''
            return xdTesting.multiremote(scenario)
                .then(() => queue += '0')
                .selectByType('phone', phones => phones
                    // Select any of none
                    .selectAny(device => device
                        .click('#button')
                    )
                    .then(result => {
                        throw new Error('Promise was unexpectedly fulfilled. Result: ' + result)
                    }, err => {
                        assert.instanceOf(err, Error)
                        assert.match(err.message, /not defined/)
                    })
                )
        })
    })
})

{'fraction_non_alphanumeric': 0.1326821326821327, 'fraction_numerical': 0.004680504680504681, 'mean_word_length': 1.38360814742968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5083432', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1174, 'n_words': 301}